/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package file.fileread;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.*;
import java.util.Vector;
import java.util.Calendar;
import javax.swing.Timer;
/**
 *
 * @author ifcouse
 */
public class Getindexstock {

    public Getindexstock() {
        //timmer();
        
    }
    
   
          // Start the timer
    
static int count=1;static StringBuffer content = new StringBuffer("");
    public static  void useSesei(){
      
        try {
            URL sUrl = new URL("http://www.settrade.com/C13_MarketSummary.jsp");
           // System.out.println("sURL " + sUrl);

         String buffer;
         
         URLConnection conn = sUrl.openConnection();
         BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"TIS-620"));
            PrintStream out = new PrintStream(new FileOutputStream("OutFile.txt"));
         while((buffer = in.readLine()) != null) {
                count++;
                content.append(count+"-->"+buffer+"\n");
                
           }
           in.close();
           //System.out.println("========================");
           //System.out.println(content.toString() + "\n");
            out.println(content.toString());
            out.close();
          // System.out.println("========================");
        } catch (Exception e){
            System.err.println("Couldn't create help URL: " + e);
        }

    }
    public static void main(String[] args) {
      new Getindexstock().useSesei();
      
      //java.awt.EventQueue.invokeLater(new Runnable() {
           // public void run() {
           //     timmer();
          //  }
        //});
      
     
    }
    
   /*  public static void timmer(){
         System.out.println("ssss");
        javax.swing.Timer  t = new javax.swing.Timer(1000, new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      //useSesei();
                      Calendar now = Calendar.getInstance();
                      int h = now.get(Calendar.HOUR_OF_DAY);
                      int m = now.get(Calendar.MINUTE);
                      int s = now.get(Calendar.SECOND);
                      System.out.println("ขณะนี้เวลา " + h + ":" + m + ":" + s +" วินาที");
                  }
              });
        t.start();
     }*/
    
}
